<template>
  <view>
    <view class="search">
      <my-search @click.native='searchClick'></my-search>
    </view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="2000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,index) in swipperList" :key="index">
        <navigator class="imgBox" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
          <image class="navigator-imgBox" :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <view class="navlist">
      <view class="nav-imgBox" v-for="(item,i) in navList" :key="i">
        <image :src="item.image_src" @click="navClickHandel(item)"></image>
      </view>
    </view>
    <view class="floorList">
      <view v-for="(item,i) in floorArr" :key="i">
        <image class="floor-title" :src="item.floor_title.image_src"></image>
        <view class="floor-img">
          <navigator class="left-floor" :url="item.product_list[i].url">
            <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}"
              mode="widthFix">
            </image>
          </navigator>
          <view class="right-floor">
            <navigator :url="item.product_list[idx].url" v-for="(itm,idx) in item.product_list" :key="idx">
              <image v-if="idx!==0" :src="itm.image_src" :style="{width:item.product_list[0].image_width+'rpx'}"
                mode="widthFix">
              </image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import minix from "@/minixs/tabbar-badge.js"
  export default {
    mixins: [minix],
    data() {
      return {
        swipperList: [],
        navList: [],
        floorArr: []
      };
    },
    onLoad() {
      this.getSwipper()
      this.getNavlist()
      this.getFloorArr()
    },
    methods: {
      async getSwipper() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.swipperList = res.message
        // uni.$showMsg('数据请求成功！')
      },
      async getNavlist() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navList = res.message
        // uni.$showMsg('数据请求成功！')
      },
      navClickHandel(item) {
        console.log(item)
        const path = {
          '分类': '/pages/cate/cate',
          '秒杀拍': '/pages/cate/cate',
          '超市购': '/pages/cate/cate',
          '母婴品': '/pages/cate/cate',
        } [item.name]
        uni.switchTab({
          url: path
        })
      },
      async getFloorArr() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        console.log(res)
        if (res.meta.status !== 200) return uni.$showMsg()
        res.message.forEach((val) => {
          val.product_list.forEach((item) => {
            item.url = `/subpkg/goods_list/goods_list?${item.navigator_url.split('?')[1]}`
          })
        })
        this.floorArr = res.message
      },
      searchClick() {
        uni.navigateTo({
          url: '/subpkg/searchPage/searchPage'
        })
      }
    }
  }
</script>

<style lang="scss">
  swiper {
    hieght: 330rpx;

    .imgBox,
    .navigator-imgBox {
      width: 100%;
      height: 100%;
    }
  }

  .navlist {
    display: flex;
    justify-content: space-around;
    margin: 15px 0px;

    .nav-imgBox,
    image {
      width: 128rpx;
      height: 140rpx;
    }
  }

  .floor-title {
    width: 100%;
    height: 60rpx
  }

  .floor-img {
    padding-left: 10rpx;
    display: flex;
  }

  .right-floor {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }

  .search {
    position: sticky;
    top: 0px;
    z-index: 9999;
  }
</style>